package com.trytry.entity;

import javax.servlet.ServletException;

import javax.servlet.Filter;

import javax.servlet.FilterChain;

import javax.servlet.FilterConfig;

import javax.servlet.ServletRequest;

import javax.servlet.ServletResponse;

import javax.servlet.http.HttpServletRequest;

import java.io.IOException;

/**

 * <p>Title: MusicWeb</p>

 * <p>Description: MusicWeb site</p>

 * <p>Copyright: Copyright (c) 2004</p>

 * <p>Company: VFrankSoft</p>

 * @author 乌小龙

 * @version 1.0

 */

public class EncodingFilter implements Filter {

 private FilterConfig config = null;

// default to ASCII

 private String targetEncoding = "ASCII";

 

 public void init(FilterConfig config) throws ServletException {

  this.config = config;

  this.targetEncoding = config.getInitParameter("encoding");

 }

 

 public void destroy() {

  config = null;

  targetEncoding = null;

 }

 

 public void doFilter(ServletRequest srequest, ServletResponse sresponse,

                   FilterChain chain) throws IOException, ServletException {

  HttpServletRequest request = (HttpServletRequest) srequest;

  request.setCharacterEncoding(targetEncoding);

  // move on to the next

  chain.doFilter(srequest, sresponse);

 }

}